home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg7.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-07  |  6.1 KB  |  204 lines

  1. /* Msg7 and Msg7PPC.elf
  2.  *
  3.  * This test program sends 1000 messages to the PPC and
  4.  * shows how long this takes.
  5.  * The Messages are send synchron and every msg must
  6.  * be replied after another.
  7.  * Each Message has a Body with the size of 3747 bytes
  8.  * and the PPC side checks if the msg is received correctly.
  9.  * The whole msg body is also checked each send if it`s
  10.  * 100% correct
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/nodes.h>
  15. #include <exec/lists.h>
  16. #include <exec/memory.h>
  17. #include <utility/tagitem.h>
  18. #include <powerup/ppclib/interface.h>
  19. #include <powerup/ppclib/message.h>
  20. #include <powerup/ppclib/tasks.h>
  21. #include <powerup/proto/ppc.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <proto/timer.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "time.h"
  28. #include "time_protos.h"
  29.  
  30. #define TEXT            "Text sent by M68k processor\n"
  31. #define KILL_ID         0x4b494c4c
  32.  
  33. #define    MSGCOUNT    1000
  34. #define    BODYSIZE    3747
  35.  
  36. struct StartupData
  37. {
  38.     ULONG    MsgCount;
  39. };
  40.  
  41. extern struct Library    *SysBase;
  42.  
  43. int    main(void)
  44. {
  45. struct Library        *PPCLibBase;
  46. struct TagItem        MyTags[10];
  47. void            *PPCPort;
  48. void            *ReplyPort;
  49. void            *StartupMsg;
  50. void            *M68kMsg;
  51. void            *PPCMsg;
  52. void            *ElfObject;
  53. void            *Task;
  54. UBYTE            *Body;
  55. struct StartupData    *StartupData;
  56. void            *MyTimerObject;
  57. ULONG            i,j;
  58.  
  59.   Printf("Opening ppc.library\n");
  60.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  61.   {
  62.     if (MyTimerObject=TimerCreateObject())
  63.     {
  64.       Printf("Loading PPC object\n");
  65.       if (ElfObject=PPCLoadObject("PROGDIR:Msg7PPC.elf"))
  66.       {
  67.         Printf("Creating reply port\n");
  68.         MyTags[0].ti_Tag    =    TAG_DONE;
  69.         if (ReplyPort = PPCCreatePort(MyTags))
  70.         {
  71.           if (StartupMsg = PPCCreateMessage(ReplyPort, 0))
  72.           {
  73.             Printf("Allocating StartupData\n");
  74.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  75.             {
  76.               StartupData->MsgCount    =    MSGCOUNT;
  77.               Printf("Creating PPC task\n");
  78.               MyTags[0].ti_Tag    =    PPCTASKTAG_STARTUP_MSG;
  79.               MyTags[0].ti_Data    =(ULONG) StartupMsg;
  80.  
  81.               MyTags[1].ti_Tag    =    PPCTASKTAG_STARTUP_MSGDATA;
  82.               MyTags[1].ti_Data    =(ULONG) StartupData;
  83.  
  84.               MyTags[2].ti_Tag    =    PPCTASKTAG_STARTUP_MSGLENGTH;
  85.               MyTags[2].ti_Data    =    0;
  86.  
  87.               MyTags[3].ti_Tag    =    PPCTASKTAG_STARTUP_MSGID;
  88.               MyTags[3].ti_Data    =    0;
  89.  
  90.               MyTags[4].ti_Tag    =    PPCTASKTAG_MSGPORT;
  91.               MyTags[4].ti_Data    =    TRUE;
  92.  
  93.               MyTags[5].ti_Tag    =    TAG_DONE;
  94.  
  95.               if (Task = PPCCreateTask(ElfObject, MyTags))
  96.               {
  97.                 if (PPCPort=(void*) PPCGetTaskAttrsTags(Task,
  98.                                                         PPCTASKINFOTAG_MSGPORT,0,
  99.                                                         TAG_END))
  100.                 {
  101.                   Printf("Allocating memory for message body\n");
  102.                   if (Body = PPCAllocVec(BODYSIZE, MEMF_PUBLIC))
  103.                   {
  104.                     Printf("Creating message...\n");
  105.                     if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  106.                     {
  107.                       Printf("Sending 1000 SYNCHRON messages with a *Body*, check the msg validation and wait for each reply...");
  108.                       TimerSetAttr(MyTimerObject,TIMERTAG_START);
  109.                       for (i=0;i<MSGCOUNT;i++)
  110.                       {
  111.                         for (j=0;j<BODYSIZE;j++)
  112.                         {
  113.                           Body[j]    =    (i+j) & 0xff;
  114.                         }
  115.  
  116.                         PPCSendMessage(PPCPort,
  117.                                        PPCMsg,
  118.                                        Body,
  119.                                        BODYSIZE,
  120.                                        0x12345678);
  121.  
  122.                         PPCWaitPort(ReplyPort);
  123.                         PPCGetMessage(ReplyPort);
  124.                       }
  125.                       TimerSetAttr(MyTimerObject,TIMERTAG_STOP);
  126.                       TimerShow(MyTimerObject);
  127.  
  128.                       Printf("Waiting for Task Finish Msg...\n");
  129.                       for (;;)
  130.                       {
  131.                         if ((M68kMsg=PPCGetMessage(ReplyPort)) == StartupMsg)
  132.                         {
  133.                           Printf("Ahh..the expected Startup=Finish Msg was received.\nNow we can savely free all resources.\n");
  134.                           break;
  135.                         }
  136.                         else
  137.                         {
  138.                           Printf("Some non replied Msg 0x%lx was found..wait\n",
  139.                                  M68kMsg);
  140.                           PPCWaitPort(ReplyPort);
  141.                         }
  142.                       }
  143.  
  144.                       Printf("Deleting message...\n");
  145.                       PPCDeleteMessage(PPCMsg);
  146.                     }
  147.                     else
  148.                     {
  149.                       Printf("Could not create Msg\n");
  150.                     }
  151.                     PPCFreeVec(Body);
  152.                   }
  153.                   else
  154.                   {
  155.                     Printf("Could not alloc mem for msg body\n");
  156.                   }
  157.                 }
  158.                 else
  159.                 {
  160.                   Printf("Could not find the PPCTask's msgport\n");
  161.                 }
  162.               }
  163.               else
  164.               {
  165.                 Printf("Could not create PPC task\n");
  166.               }
  167.               PPCFreeVec(StartupData);
  168.             }
  169.             else
  170.             {
  171.               Printf("Could not alloc Startup Data\n");
  172.             }
  173.             PPCDeleteMessage(StartupMsg);
  174.           }
  175.           else
  176.           {
  177.             Printf("Could not create Startup message\n");
  178.           }
  179.           PPCDeletePort(ReplyPort);
  180.         }
  181.         else
  182.         {
  183.           Printf("Could not create reply port\n");
  184.         }
  185.         Printf("Unloading PPC object\n");
  186.         PPCUnLoadObject(ElfObject);
  187.       }
  188.       else
  189.       {
  190.         Printf("Could not load the elfobject\n");
  191.       }
  192.       TimerDeleteObject(MyTimerObject);
  193.     }
  194.     Printf("Closing ppc.library\n");
  195.     CloseLibrary(PPCLibBase);
  196.   }
  197.   else
  198.   {
  199.     Printf("Could not open ppc.library v44+\n");
  200.   }
  201.   return(0);
  202. }
  203.  
  204.